let obj = { name: 'rays77', age: '17' }

console.log(obj.__proto__)
console.log('obj.__proto__ -> ', obj.__proto__ === Object.prototype)
//通过字面量构造出来的对象，其[[prototype]]指向Object.prototype

console.log('=================================================================')

function Foo(name, age, sex) {
  this.name = name
  this.age = age
  this.sex = sex
}

console.log('Foo -> constructor', Foo.constructor)

Foo.prototype.belief = function () {
  console.log('量变是质变的必要准备，质变是量变积累到一定程度的必然结果！')
}

let f1 = new Foo()
let f2 = new Foo('rays77', 18, '男')

Foo.length = 200
let f = {} //一个继承自 Foo.prototype 的新对象被创建。
console.log('f -> Foo.prototype ? 結果=> ', typeof f === typeof Foo.prototype)
console.log('Foo.length -> ', f.length) // undefined

console.log('=================================================================')

//注意，千万不要使用字面量方式来定义属性和方法，否则原有属性和方法会被重写：
function Fn() {}

// 定义属性
Fn.prototype.a = 1
Fn.prototype.b = 2

Fn.prototype.d = function () {
  return this.a + this.b
}

var foo1 = new Fn()
console.log('foo1 - > ', foo1)
console.log('foo1.d() - > ', foo1.d())
console.log('foo1.a -> ', foo1.a)
console.log('foo1.b -> ', foo1.b)

console.log('--------------------经过字面量定义方法后---------------------')

// 字面量定义方法，原型被重写，原有属性和方法被更新
Fn.prototype = {
  c: function () {
    return this.a + this.b
  }
}
// Fn.prototype.c = function () {
//   return this.a + this.b
// }

var foo = new Fn()
console.log('foo === Fn.prototype? 結果=> ', typeof foo === typeof Fn.prototype)
console.log('foo - > ', foo) //Fn {}
console.log('foo.c() - > ', foo.c()) // NaN
console.log('foo.a -> ', foo.a) // undefined
console.log('foo.b -> ', foo.b) // undefined
